<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/24 0024
 * Time: 下午 9:32
 */
namespace app\api\controller;

use app\common\controller\Api;

class Weixin extends Api
{
	
	protected $noNeedLogin = ['index', 'getshareconfig'];
	
	/**
	 * 响应微信的方法
	 */
	public function index()
	{
		echo $_GET['echostr'];
	}
	/**
	 * h5分享配置
	 */
	public function getShareConfig() {
		$url = urldecode($this->request->post('url'));
		
		
		$config = config('weixin.public');
		$appId = $config['app_id'];
		$weixin = new \app\common\library\Weixin($appId);
		$resData = [
			'noncestr' => $weixin->createNoncestr(),
			'timestamp' => (string)time(),
			'jsapi_ticket' => $weixin->getTicket(),
			'url' => $url,
		];
		
		ksort($resData);
		$String = \app\common\library\Weixin::formatBizQueryParaMap($resData, false);
		
		$resData['app_id'] = $appId;
		$resData['signature'] = sha1($String);
		
		$this->success('成功', $resData);
	}
}
